<template>
  <div class="mybill">
    <div class="mybill-top">
      <i @click="bill_Back"></i>
      <h4 @click="bill_my">我的账单</h4>
      <p v-show="!is_show_history && show_tips" @click="bill_repayment">还款</p>
    </div>
    <div class="bill-tab">
      <div class="tab-item" :class="showPage('last')" @click="setPage('last')">
        <p>已出账单({{lastMonth}}月)</p>
        <i></i>
      </div>
      <div class="tab-item" :class="showPage('this')" @click="setPage('this')">
        <p>未出账单({{thisMonth}}月)</p>
        <i></i>
      </div>
      <div class="tab-item" :class="showPage('history')" @click="setPage('history')">
        <p>历史账单</p>
        <i></i>
      </div>
    </div>
    <wealth-le-shell-bill-history v-if="is_show_history"></wealth-le-shell-bill-history>
    <wealth-le-shell-bill-month v-else></wealth-le-shell-bill-month>
    <div class="current-repayment-tips" :class="{show: isShowRepaymentTips}">
      <div class="current-cont">
        <h4>乐钱包余额不足</h4>
        <p>请先充值到乐钱包后再还款</p>
        <div class="current-bottom-line"></div>
        <span class="current-left" @click="cancelRepayment">取消</span>
        <span class="current-right" @click="goRecharge">去充值</span>
      </div>
    </div>
  </div>
</template>

<script>
import WealthLeShellBillHistory from "~/components/WealthLeShellBillHistory.vue";
import WealthLeShellBillMonth from "~/components/WealthLeShellBillMonth.vue";

export default {
  components: {
    WealthLeShellBillHistory,
    WealthLeShellBillMonth
  },
  data: function() {
    return {
      isShowRepaymentTips: false
    };
  },
  computed: {
    currency_code() {
      return this.$store.state.wealthLeShell.currency_code;
    },
    bill_month_tips() {
      return this.$store.state.wealthLeShellBill.bill_month_tips;
    },
    unbill_month_tips() {
      return this.$store.state.wealthLeShellBill.unbill_month_tips;
    },
    current_bill_page() {
      return this.$store.state.wealthLeShellBill.current_bill_page;
    },
    show_tips() {
      // return true; //test
      let is_show = false;
      if (this.current_bill_page == "last") {
        is_show = this.bill_month_tips != "已还清";
      } else if (this.current_bill_page == "this") {
        is_show = this.unbill_month_tips != "已还清";
      }
      return is_show;
    },
    is_show_history() {
      return this.$store.state.wealthLeShellBill.is_show_history;
    },
    lastMonth() {
      return this.$store.state.wealthLeShellBill.lastMonth;
    },
    thisMonth() {
      return this.$store.state.wealthLeShellBill.thisMonth;
    }
  },
  mounted() {},
  methods: {
    async get_repayment_data() {
      let { data: rs } = await this.$axios.post(
        "?ct=api&ac=get_repayment_data"
      );
      this.$store.commit("wealthLeShell/SET_repayment_data", rs);
      if (rs.code == 0) {
        let wallet = rs.data.wallet;
        if (wallet.length < 1) {
          this.isShowRepaymentTips = true;
        } else {
          let has_cash = false;
          wallet.forEach((item, index, array) => {
            if (item.amount > 0) {
              has_cash = true;
              return;
            }
          });
          if (has_cash) {
            this.$router.push("/WealthLeShellRepayment");
          } else {
            this.isShowRepaymentTips = true;
          }
        }
      } else {
        this.$toast(rs.msg);
      }
    },

    bill_Back() {
      // return; //test
      this.$router.go(-1);
    },
    bill_my() {
    },
    bill_repayment() {
      this.get_repayment_data();
      // return; //test
      // this.$router.push("/WealthLeShellRepayment");
    },
    //取消
    cancelRepayment() {
      this.isShowRepaymentTips = false;
    },
    //去充值
    goRecharge() {
      this.$router.push({
        path: "/wealth/recharge",
        query: { code: this.currency_code }
      });
    },
    showPage(str) {
      return {
        active: str === this.current_bill_page ? true : false
      };
    },
    setPage(str) {
      let is_history = str === "history" ? true : false;
      this.$store.commit("wealthLeShellBill/SET_is_show_history", is_history);
      this.$store.commit("wealthLeShellBill/SET_current_bill_page", str);
    }
  }
};
</script>

<style scoped>
.mybill {
}
.mybill-top {
  display: flex;
  /* height: 88px; */
  line-height: 89px;
  font-family: "PingFangSC-Medium";
  font-size: 36px;
  color: rgb(41, 41, 41);
  background-color: #fff;
}
.mybill-top i {
  margin-left: 30px;
  margin-top: 25px;
  width: 21px;
  height: 38px;
  background: url("~assets/img/black_blue@2x.png") no-repeat;
  background-size: 21px 38px;
}
.mybill-top h4 {
  flex: 1;
  text-align: center;
}
.mybill-top p {
  margin-right: 30px;
  font-family: "PingFangSC-Regular";
  font-size: 30px;
  color: #2086f9;
}

.bill-tab {
  white-space: nowrap;
  height: 70px;
  line-height: 70px;
  font-size: 30px;
  text-align: center;
  color: rgb(41, 41, 41);
  font-family: "PingFangSC-Regular";
  background-color: #fff;
}
.tab-item {
  display: inline-block;
}
.tab-item:first-child {
  float: left;
  margin-left: 30px;
}
.tab-item:last-child {
  float: right;
  margin-right: 30px;
}


.tab-item.active p {
  color: #2086f9;
  font-family: "PingFangSC-Medium";
}
.tab-item.active i {
  display: block;
  margin: auto;
  margin-top: -6px;
  height: 4px;
  width: 32px;
  background-color: #2086f9;
  border-radius: 2px;
}

.current-repayment-tips {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  background-color: rgba(0, 0, 0, 0.4);
  z-index: 2000;
}
.current-repayment-tips.show {
  display: block;
}
.current-cont {
  position: absolute;
  left: 50%;
  top: 50%;
  margin-left: -270px;
  margin-top: -163px;
  height: 326px;
  width: 540px;
  text-align: center;
  font-size: 34px;
  font-family: "PingFangSC-Regular";
  color: rgb(41, 41, 41);
  background-color: #fff;
  border-radius: 16px;
}
.current-bottom-line {
  position: absolute;
  padding-top: 32px;
  width: 100%;
  height: 2px;
  border-bottom: 2px solid #ededf0;
}
.current-repayment-tips h4 {
  margin-top: 60px;
}
.current-repayment-tips p {
  margin-top: 22px;
  font-size: 26px;
  color: rgb(153, 153, 153);
}
.current-repayment-tips .current-left {
  margin-top: 94px;
  margin-left: 100px;
  color: #2086f9;
  height: 88px;
  float: left;
}
.current-repayment-tips .current-right {
  margin-top: 94px;
  margin-right: 86px;
  float: right;
  height: 88px;
  color: #2086f9;
}
</style>
